package Chapter2.Comparing.c9.Communication;

import java.util.Random;

public class Consumer extends Thread {
    private Container<BaoZi> container;
    private Integer sum;

   /* public Consumer(Integer sum) {
        this.sum = sum;
    }*/

    public Consumer(Container<BaoZi> container, Integer sum, String name) {
        this(name);
        this.container = container;
        this.sum = sum;

    }

    public Consumer(String name) {
    }

    @Override
    public void run() {
        Random random = new Random();
        for (int i=0; i<sum;i++) {
            BaoZi baozi = container.fetch();
            System.out.println(Thread.currentThread().getName()+"买了一个"+baozi);
            try {
                Thread.sleep(1000+random.nextInt(4000));
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
